﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp1;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    private string currentOperator = "";
    private double firstNumber = 0;
    private bool isNewEntry = true;


    public MainWindow()
    {
        InitializeComponent();


        // 创建 20 个按钮文本
        List<string> buttons = new List<string>();
        for (int i = 1; i <= 20; i++)
        {
            buttons.Add("按钮 " + i);
        }

        // 绑定到 ItemsControl
        ButtonsList.ItemsSource = buttons;


        var articles = new List<string>();
        articles.Add("开始学习  JavaScript 的学习教程");
        articles.Add("Python 的学习教程");
        articles.Add("C++ 的学习教程");
        articles.Add("C# 的学习教程");
        articles.Add("Go 的学习教程");
        articles.Add("Rust 的学习教程");
        articles.Add("Swift 的学习教程");
        articles.Add("Kotlin 的学习教程");
        articles.Add("Ruby 的学习教程");
        articles.Add("PHP 的学习教程");
        articles.Add("Perl 的学习教程");
        articles.Add("Lua 的学习教程");
        articles.Add("Shell 的学习教程");
        articles.Add("Groovy 的学习教程");
        articles.Add("Scala 的学习教程");
        articles.Add("Haskell 的学习教程");
        articles.Add("Elixir 的学习教程");
        articles.Add("R 的学习教程");
        articles.Add("Prolog 的学习教程");
        articles.Add("Lisp 的学习教程");
        articles.Add("Smalltalk 的学习教程");
        articles.Add("Objective-C 的学习教程");
        articles.Add("Delphi 的学习教程");
        articles.Add("Visual Basic 的学习教程");
        articles.Add("Cobol 的学习教程");
        articles.Add("Fortran 的学习教程");
        articles.Add("Ada 的学习教程");
        articles.Add("ABAP 的学习教程");
        articles.Add("开始学习  PL/SQL 的学习教程");

        // 绑定到 ItemsControl
        ArticlesList.ItemsSource = articles;
    }


    private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        // 创建窗口并显示
        MyWindow window = new MyWindow();
        window.Show(); // 非模态窗口
        // window.ShowDialog(); // 模态窗口，阻塞当前窗口
    }


    private void Number_Click(object sender, RoutedEventArgs e)
    {
        string number = (string)((System.Windows.Controls.Button)sender).Content;
        if (isNewEntry)
        {
            Display.Text = number;
            isNewEntry = false;
        }
        else
        {
            Display.Text += number;
        }
    }

    private void Operator_Click(object sender, RoutedEventArgs e)
    {
        string op = (string)((System.Windows.Controls.Button)sender).Content;
        if (double.TryParse(Display.Text, out firstNumber))
        {
            currentOperator = op;
            isNewEntry = true;
        }
    }

    private void Equal_Click(object sender, RoutedEventArgs e)
    {
        if (double.TryParse(Display.Text, out double secondNumber))
        {
            double result = 0;
            switch (currentOperator)
            {
                case "+": result = firstNumber + secondNumber; break;
                case "-": result = firstNumber - secondNumber; break;
                case "*": result = firstNumber * secondNumber; break;
                case "/":
                    if (secondNumber != 0) result = firstNumber / secondNumber;
                    else
                    {
                        Display.Text = "错误";
                        return;
                    }

                    break;
            }

            Display.Text = result.ToString();
            isNewEntry = true;
        }
    }

    private void Clear_Click(object sender, RoutedEventArgs e)
    {
        Display.Text = "0";
        firstNumber = 0;
        currentOperator = "";
        isNewEntry = true;
    }

    private void showDockPanel(object sender, RoutedEventArgs e)
    {
        DockPanelWindow dockPanelWindow = new DockPanelWindow();
        dockPanelWindow.Show();
    }

    private void showWrapPanel(object sender, RoutedEventArgs e)
    {
        WrapPanelWindow wrapPanelWindow = new WrapPanelWindow();
        wrapPanelWindow.Show();
    }

    private void showGrid(object sender, RoutedEventArgs e)
    {
        GridWindow gridWindow = new GridWindow();
        gridWindow.Show();
    }
    
    private void showTreeViewWindow(object sender, RoutedEventArgs e)
    {
        TreeViewWindow treeViewWindow = new TreeViewWindow();
        treeViewWindow.Show();
    }

    private void showMenuWindow(object sender, RoutedEventArgs e)
    {
        new MenuWindow().Show();
    }

}

public class ButtonViewModel
{
    public string ButtonText { get; set;
    }

}